import global from '@/utils/global'
import http from '@/utils/request'

export function getOrgList(deptName, deptStatus) {
  return http({
    url: http.adornUrl(global.upms + '/org/list'),
    method: 'post',
    data: http.adornData({
      'name': deptName === '' ? null : deptName,
      'status': deptStatus === '' ? null : deptStatus
    })
  })
}

export function addOrg(deptName, deptStatus, deptSort, deptParentId) {
  return http({
    url: http.adornUrl(global.upms + '/org'),
    method: 'post',
    data: http.adornData({
      'name': deptName,
      'sort': deptSort === null ? 99 : deptSort,
      'status': deptStatus,
      'parentId': deptParentId
    })
  })
}

export function updateOrg(deptId, deptName, deptStatus, deptSort, deptParentId) {
  return http({
    url: http.adornUrl(global.upms + '/org/' + deptId),
    method: 'patch',
    data: http.adornData({
      'id': deptId,
      'name': deptName,
      'sort': deptSort === null ? 99 : deptSort,
      'status': deptStatus,
      'parentId': deptParentId
    })
  })
}

export function deleteOrg(deptId) {
  return http({
    url: http.adornUrl(global.upms + '/org/batch/' + deptId),
    method: 'delete'
  })
}

export function deleteBatchOrg(deptIds) {
  return http({
    url: http.adornUrl(global.upms + '/org/delete/batches'),
    headers: { // application/json; charset=utf-8 //application/x-www-form-urlencoded; charset=utf-8
      'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
    },
    method: 'post',
    data: http.adornData({
      'ids': deptIds
    }, true, 'form')
  })
}
